import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useTokenStore = defineStore('token',()=> {
	const token = ref('')
	
	// 定义修改token的方法
	    const setToken = (newToken)=>{
	        token.value=newToken
	    }
	
	    //移出token的方法
	    const removeToken = ()=>{
	        token.value=''
	    }
	    return{token,setToken,removeToken}	
  
},{
	//持久化存储
	persist:{
		storage: {
		        setItem(key, value) {
		          uni.setStorageSync(key, value) // [!code warning]
		        },
		        getItem(key) {
		          return uni.getStorageSync(key) // [!code warning]
		        },
		      },
	},
	unistorage:true
})
export const Store={
	getToken:()=>{
		return localStorage.getItem("token")
	},
	setToken:(token)=>{
		localStorage.setItem("token",token)
	}
}